<!-- 使用 type="home" 属性设置首页，其他页面不需要设置，默认为page；推荐使用json5，更强大，且允许注释 -->
<route lang="json5">
{
  style: {
    navigationStyle: 'custom',
    navigationBarTitleText: '消息详情',
  },
}
</route>
<template>
  <view class="bg overflow-hidden pt-2" :style="{ marginTop: safeAreaInsets?.top + 'px' }">
    <view
      class="flex mt-8 justify-between items-center"
      style="padding-right: 0.75rem; padding-left: 1.31rem"
    >
      <img src="@/static/app/custom-icon/ze-arrow-left 1@1x.png" alt="" @click="goView" />
      <text>我是紫涵</text>
      <img src="@/static/app/custom-icon/群组%208@1x.png" height="6" alt="" />
    </view>

    <view class="line"></view>
    <view class="flex flex-col">
      <view class="item" v-for="item in list">
        <view class="flex items-center justify-start flex-row-reverse" v-if="item.selfFlag">
          <img :src="item.icon" alt="" />
          <view class="chat-right">
            {{ item.message }}
          </view>
        </view>

        <view class="flex items-center justify-start" v-else>
          <img :src="item.icon" alt="" />
          <view class="chat-left">{{ item.message }}</view>
        </view>
      </view>
    </view>

    <view class="bottom flex items-center">
      <img src="@/static/app/custom-icon/iconPark-voice-message%201@1x.png" alt="" />
      <view class="input"></view>
      <img
        src="@/static/app/custom-icon/if-laughing%201@1x.png"
        alt=""
        style="margin-left: 0.44rem"
      />
      <img src="@/static/app/custom-icon/mb-plus-o@1x.png" alt="" style="margin-left: 0.69rem" />
    </view>
  </view>
</template>

<script lang="ts" setup>
defineOptions({
  name: 'Home',
})

// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
function goView() {
  uni.navigateBack()
}
const list = ref([
  {
    icon: new URL('@/static/app/custom-icon/avatar1.png', import.meta.url).href,
    message: '你好',
    selfFlag: true,
  },
  {
    icon: new URL('@/static/app/custom-icon/avatar2.png', import.meta.url).href,
    message: '你好呀~',
    selfFlag: false,
  },
  {
    icon: new URL('@/static/app/custom-icon/avatar2.png', import.meta.url).href,
    message: '呆呆是蠢蛋',
    selfFlag: false,
  },
])
</script>

<style scoped>
.main-title-color {
  color: #d14328;
}

.bg {
  box-sizing: border-box;
  height: 100vh;
  padding-bottom: 3.56rem;
  background: linear-gradient(
    86.39deg,
    rgba(159, 220, 250, 0.6) 4.39%,
    rgba(159, 219, 250, 0.61) 44.88%,
    rgba(170, 198, 254, 0.45) 127.07%
  );
}

.item {
  padding-top: 1.31rem;
  padding-right: 0.88rem;
  padding-left: 0.88rem;
  img {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
  }

  .chat-left,
  .chat-right {
    position: relative;
    padding: 0.44rem 1.5rem 0.44rem 1.25rem;
    background-color: rgb(204, 247, 131);
    border-radius: 0 0.3rem 0.3rem;
  }

  .chat-left {
    margin-left: 1rem;
  }

  .chat-right {
    margin-right: 1rem;
  }

  .chat-left::before {
    position: absolute;
    /*垂直居中计算*/
    top: 50%;
    /* 在div左边展示 偏移量为 边框宽度*2 即5*2px */
    left: -0.9rem;
    width: 0;
    height: 0;
    content: '';
    /* 边框宽度为5px 颜色透明(也就是隐藏) */
    border: 0.5rem solid transparent;
    /* 箭头向左 则右边框显示 */
    border-right-color: rgb(204, 247, 131);
    transform: translateY(-50%);
  }

  .chat-right::before {
    position: absolute;
    top: 50%;
    /* 在div右边展示 偏移量为 边框宽度*2 即5*2px */
    right: -0.9rem;
    width: 0;
    height: 0;
    content: '';
    /* 边框宽度为5px 颜色透明(也就是隐藏) */
    border: 0.5rem solid transparent;
    /* 箭头向右 则左边框显示 */
    border-left-color: rgb(204, 247, 131);
    transform: translateY(-50%);
  }
}

.bottom {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 5.06rem;
  padding: 0 0.63rem;
  background-color: rgb(239, 239, 239);
  img {
    width: 1.69rem;
    height: 1.69rem;
  }

  .input {
    width: 15.81rem;
    height: 2.75rem;
    margin-left: 0.19rem;
    background-color: white;
    border-radius: 0.5rem;
  }
}

.line {
  width: 100%;
  height: 0.06rem;
  margin-top: 0.44rem;
  background-color: #bbbbbb;
}
</style>
